import React from 'react';
import { connect } from 'dva'
import { Card, Divider, Table } from 'antd';
import DescriptionList from 'components/DescriptionList';
import PageHeaderLayout from 'components/Layout/PageHeaderLayout';
import { LwjTable } from "components";
import moment from 'moment';
import { receiptStatus } from "utils/enumConfig"
import { financialSettlementStatus, financialBusinessType } from "utils/enumConfig"

const { Description } = DescriptionList;

const settlementsColumns = [
  {
    title: '单据编号',
    dataIndex: 'orderId',
    key: 'orderId',
    width: "10%",
  },
  {
    title: '业务类型',
    dataIndex: 'businessType',
    key: 'businessType',
    width: "10%",
    render: (text, record, index) => (financialBusinessType[record.businessType])
  },
  {
    title: "结算类型",
    dataIndex: 'settlementType',
    key: 'settlementType',
    width: "10%",
    render: (text, record, index) => (
      record.settlementType === "PAYABLE" ? "应付" : "应收"
    )
  },
  {
    title: "金额",
    dataIndex: 'settlementMoney',
    key: 'settlementMoney',
    width: "10%",
    render: (text, record, index) => (
      record.settlementMoney.toFixed(2)
    )
  },
];
const offsetsColumns = [
  {
    title: '冲抵收款单号',
    dataIndex: 'receiptNum',
    key: 'receiptNum',
    width: "10%",
  },
  {
    title: '冲抵金额(元)',
    dataIndex: 'offset',
    key: 'offset',
    width: "10%",
    render: (text, record, index) => (record.offset.toFixed(2))
  }
];


const settlementBatchDetails = ({ location, dispatch, settlementBatchDetail, loading }) => {
  const { currentItemDetail } = settlementBatchDetail;
  let loadedAll = _.isEmpty(currentItemDetail);
  let loadedReceipter = true;


  const breadcrumbList = [
    {
      title: '财务管理',
    }, {
      title: '结算批次',
      href: '/settlementBatch'
    }, {
      title: '结算批次详情',
    }
  ];

  return (
    <PageHeaderLayout title="结算批次详情页" breadcrumbList={breadcrumbList}>
      <Card bordered={false}>
        <DescriptionList
          style={{
            marginBottom: 32
          }}>
          <Description term="结算人">{currentItemDetail.creatorName}</Description>
          <Description term="结算总金额">￥ {currentItemDetail.totalMoney} </Description>
          <Description term="结算时间">{moment(currentItemDetail.createTime).format("YYYY-MM-DD HH:mm:ss")}</Description>
        </DescriptionList>

        <DescriptionList
          size="large"
          title="结算申请单"
          style={{
            marginBottom: 32
          }}>
          <Table rowKey="id" pagination={false} dataSource={currentItemDetail.settlementApplySummary} columns={settlementsColumns} />
        </DescriptionList>
      </Card>
      {/* {!loadedAll && currentItemDetail.settlementType === "RECEIVABLE" && <Card bordered={false}>
        <DescriptionList
          size="large"
          title="收款单信息"
          style={{
            marginBottom: 32
          }}>
          <Description term="收款单号">{currentItemDetail.receiptOffSummary.num}</Description>
          <Description term="付款方式">{currentItemDetail.receiptOffSummary.paymentType}</Description>
          <Description term="收款人">{currentItemDetail.receiptOffSummary.receipter.name}</Description>
          <Description term="应收金额">{currentItemDetail.receiptOffSummary.receivable.toFixed(2)} 元</Description>
          <Description term="实收金额">{currentItemDetail.receiptOffSummary.received.toFixed(2)} 元</Description>
          <Description term="剩余金额">{currentItemDetail.receiptOffSummary.availableBalance.toFixed(2)} 元</Description>
          <Description term="审核状态">{currentItemDetail.receiptOffSummary.auditStatus === "NULL" ? "待审核" :
            currentItemDetail.receiptOffSummary.auditStatus === "AUDIT_SUCCESS" ? "审核通过" :
              currentItemDetail.receiptOffSummary.auditStatus === "AUDIT_FAIL" ? "审核未通过" : ""}</Description>
        </DescriptionList>
      </Card>
      } */}
      <Card>
        <DescriptionList
          size="large"
          title="冲抵记录"
          style={{
            marginBottom: 32
          }}>
          <Table rowKey="id" pagination={false} dataSource={currentItemDetail.offsetSummaries} columns={offsetsColumns} />
        </DescriptionList>
        <Divider style={{
          marginBottom: 32
        }} />
      </Card>
    </PageHeaderLayout>
  )
};

export default connect(({ settlementBatchDetail, loading }) => ({ settlementBatchDetail, loading }))(settlementBatchDetails)
